package com.googlecode.dgwt.client.dijit.resource.template;

import com.googlecode.dgwt.client.DGWT;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class TemplateFragments {

    
    /**
     * Gets a simple table with just one cell to enable sizing width and/or height 100%.
     * 
     * @return a template fragment
     */
    public String getSimpleTable(String content) {
        return (
                "<table" +
                    " border='0'" +
                    " cellpadding='0'" +
                    " cellspacing='0'" +
                    " dojoAttachPoint='sizeableElement'" +
                    " >" +
                    "<tr>" +
                        "<td" +
                            " dojoAttachPoint='styleElement" + (content.isEmpty() ? ",containerElement" : "") +  "'" +
                            " >" +
                            content +
                        "</td>" +
                    "</tr>" +
                "</table>"
        );
    }
  
    
    /**
     * @return a template fragment
     */
    protected String getScrollBox(String content){
        if (DGWT.isEnableFullWidthHeightForScrollBox()){
            return getSimpleTable(getScrollDiv(content));
        }
        return getScrollDiv(content);
    }
    
    
    /**
     * @return a template fragment
     */
    protected String getScrollDiv(String content){
        if (DGWT.isEnableFullWidthHeightForScrollBox()){
            return getRelativeScrollDiv(content);
        }
        return getStaticScrollDiv(content);
    }

    
    /**
     * @return a template fragment
     */
    public final String getStaticScrollDiv(String content) {
        return (
                "<div" +
                    (content.isEmpty() ? " dojoAttachPoint='containerElement,scrollableElement'" : "") +
                    " wairole='presentation'" +
                    " style='" +
                        " overflow: auto;" +
                    " >" +
                    content +
                "</div>"
        );
    }

        
    /**
     * @return a template fragment
     */
    public final String getRelativeScrollDiv(String content) {
        return (
                "<div" +
                    (content.isEmpty() ? " dojoAttachPoint='containerElement,scrollableElement'" : "") +
                    " wairole='presentation'" +
                    " style='" +
                        " position: relative;" +
                        " overflow: auto;" +
                        " height: 100%;" +
                        " width: 100%;'" +
                    " >" +
                    content +
                "</div>"
        );
    }

        
    /**
     * @return a template fragment
     */
    public final String getAbsoluteScrollDiv(String content) {
        return (
                "<div" +
                    (content.isEmpty() ? " dojoAttachPoint='containerElement,scrollableElement'" : "") +
                    " wairole='presentation'" +
                    " style='" +
                        " position: absolute;" +
                        " overflow: auto;" +
                        " height: 100%;" +
                        " width: 100%;'" +
                    " >" +
                    content +
                "</div>"
        );
    }

    
    /**
     * @return a template fragment
     */
    public String getRelativeDiv(String content) {
        return (
                "<div" +
                    (content.isEmpty() ? " dojoAttachPoint='containerElement'" : "") +
                    " style='" +
                        " position: relative;" +
                        " height: 100%;" +
                        " width: 100%;'" +
                    " >" +
                    content +
                "</div>"
        );
    }

}
